package com.jeesite.modules.task.receive.service;

import com.alibaba.fastjson.JSONObject;
import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.idgen.IdGen;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.service.CrudService;
import com.jeesite.common.utils.SpringUtils;
import com.jeesite.modules.backlog.service.DcSupBacklogService;
import com.jeesite.modules.common.dao.SysBasicDao;
import com.jeesite.modules.common.entity.SysBasicUser;
import com.jeesite.modules.common.service.SysMsgService;
import com.jeesite.modules.file.entity.FileUpload;
import com.jeesite.modules.file.utils.FileUploadUtils;
import com.jeesite.modules.home.entity.DcSupTaskActionExplain;
import com.jeesite.modules.msg.entity.content.PcMsgContent;
import com.jeesite.modules.msg.utils.MsgPushUtils;
import com.jeesite.modules.sys.utils.UserUtils;
import com.jeesite.modules.task.action.dao.DcSupTaskActionDao;
import com.jeesite.modules.task.action.entity.DcSupTaskAction;
import com.jeesite.modules.task.action.service.DcSupTaskActionService;
import com.jeesite.modules.task.audit.service.DcSupTaskAuditService;
import com.jeesite.modules.task.deploy.entity.DcSupTaskInfo;
import com.jeesite.modules.task.deploy.entity.OfficeUser;
import com.jeesite.modules.task.deploy.service.DcSupTaskInfoService;
import com.jeesite.modules.task.feedback.entity.*;
import com.jeesite.modules.task.feedback.service.DcSupTaskFeedbackService;
import com.jeesite.modules.task.receive.dao.TaskReceiveDao;
import com.jeesite.modules.task.receive.entity.TaskReceiveDto;
import com.jeesite.modules.task.status.service.DcSupTaskStatusService;
import com.jeesite.modules.utils.Dict;
import com.jeesite.modules.utils.MinioUtils;
import com.jeesite.modules.yzw.entity.MsgDetail;
import com.jeesite.modules.yzw.service.LehandYzwPushTask;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 任务过程审核表Service
 * @author zrr
 * @version 2022-03-02
 */
@Service
@Transactional(readOnly=false)
public class TaskReceiveService extends CrudService<TaskReceiveDao, TaskReceiveDto> {

	@Autowired
	private TaskReceiveDao taskReceiveDao;
	@Autowired
	private DcSupTaskAuditService dcSupTaskAuditService;
	@Autowired
	private DcSupTaskFeedbackService dcSupTaskFeedbackService;
	@Autowired
	private DcSupTaskActionService dcSupTaskActionService;
	@Autowired
	private DcSupTaskInfoService dcSupTaskInfoService;
	@Autowired
	private DcSupTaskStatusService dcSupTaskStatusService;
	@Autowired
	private LehandYzwPushTask lehandYzwPushTask;
	@Autowired
	private SysBasicDao sysBasicDao;
	@Autowired
	private DcSupTaskActionDao dcSupTaskActionDao;
	@Autowired
	private SysMsgService sysMsgService;
	@Autowired
	private DcSupBacklogService dcSupBacklogService;

	/**
	 * 获取单条数据
	 * @param dcSupTaskAudit
	 * @return
	 */
	@Override
	public TaskReceiveDto get(TaskReceiveDto dcSupTaskAudit) {
		return super.get(dcSupTaskAudit);
	}
	
	/**
	 * 查询分页数据
	 * @param dcSupTaskAudit 查询条件
	 * @return
	 */
	@Override
	public Page<TaskReceiveDto> findPage(TaskReceiveDto dcSupTaskAudit) {
		return super.findPage(dcSupTaskAudit);
	}
	
	/**
	 * 查询列表数据
	 * @param dcSupTaskAudit
	 * @return
	 */
	@Override
	public List<TaskReceiveDto> findList(TaskReceiveDto dcSupTaskAudit) {
		return super.findList(dcSupTaskAudit);
	}
	
	/**
	 * 保存数据（插入或更新）
	 * @param dcSupTaskAudit
	 */
	@Override
	@Transactional(readOnly=false)
	public void save(TaskReceiveDto dcSupTaskAudit) {
		super.save(dcSupTaskAudit);
		// 保存上传图片
		FileUploadUtils.saveFileUpload(dcSupTaskAudit, dcSupTaskAudit.getId(), "dcSupTaskAudit_image");
		// 保存上传附件
		FileUploadUtils.saveFileUpload(dcSupTaskAudit, dcSupTaskAudit.getId(), "dcSupTaskAudit_file");
	}
	
	/**
	 * 更新状态
	 * @param dcSupTaskAudit
	 */
	@Override
	@Transactional(readOnly=false)
	public void updateStatus(TaskReceiveDto dcSupTaskAudit) {
		super.updateStatus(dcSupTaskAudit);
	}
	
	/**
	 * 删除数据
	 * @param dcSupTaskAudit
	 */
	@Override
	@Transactional(readOnly=false)
	public void delete(TaskReceiveDto dcSupTaskAudit) {
		super.delete(dcSupTaskAudit);
	}

	public Page<TaskReceiveDto> listDataHis(TaskReceiveDto taskReceive) {
		List<TaskReceiveDto> taskReceiveDtos = taskReceiveDao.listDataHis(taskReceive);
		return taskReceive.getPage().setList(taskReceiveDtos);
	}

    public List<DcSupTaskFeedback> getFeedbackList(String id) {
		return taskReceiveDao.getFeedbackList(id);
    }

    public String feedback(DcSupTaskFeedback taskFeedback) {
		// 反馈时，将此处的消息置为已读
		// 将审核驳回的单条消息置为已读
		sysMsgService.makeMsgReadByBiz(taskFeedback.getId(), "audit_reject_feedback", UserUtils.getUser().getUserCode());
		// 将催办的多条消息置为已读，此处没有控制，只要反馈都执行
		DcSupTaskAction tempAction = dcSupTaskActionService.get(taskFeedback.getActionId());
		sysMsgService.makeMsgReadByBiz(taskFeedback.getTaskId() + "_" + tempAction.getLeaderOrgCode(), "feedback_msg", null);

		if ("2".equals(taskFeedback.getFeedbackStatus())) {
			//修改action表的taskStatus,在第一次反馈和最后一次反馈的时候
			Integer firstOrLast = dcSupTaskFeedbackService.isFirstOrLast(taskFeedback.getActionId());
			DcSupTaskAction action = new DcSupTaskAction();
			action.setId(taskFeedback.getActionId());
			//每次反馈选择的状态写入到action表
//			action.setTaskProgress(taskFeedback.getFeedbackProgress());
			if(taskFeedback.getFeedbackProgress().equals("1")){//反馈的序时推进
				action.setTaskProgress("3");//任务的序时推进
			}
			if(taskFeedback.getFeedbackProgress().equals("2")){//反馈的滞后时序
				action.setTaskProgress("1");//任务的进度滞后
			}
			if(taskFeedback.getFeedbackProgress().equals("3")){//反馈的已完成
				action.setTaskProgress("4");//任务的已完成
			}
			if(taskFeedback.getFeedbackProgress().equals("4")){//反馈的未完成
				action.setTaskProgress("5");//任务的未完成
			}
			//最后一次反馈,把转办的设置为已办20230411变成每次反馈都把转办的置为已办
			if ("1".equals(tempAction.getTransferFlag())) {
				dcSupBacklogService.doBacklog(action.getId(),"task_transfer");
			}
			if (firstOrLast == 0) {
				action.setTaskStatus(Dict.TaskStatus.STATUS_3);
				dcSupTaskActionService.update(action);
			} else if (firstOrLast == 1) {
				action.setTaskStatus(Dict.TaskStatus.STATUS_3);
				action.setRemarks3("last");
				dcSupTaskActionService.update(action);

			}else{
				dcSupTaskActionService.update(action);
			}
		}

		// 写入审批表，反馈时间只记录其第一次反馈的时间
		DcSupTaskFeedback tempTaskFeedback = dcSupTaskFeedbackService.get(taskFeedback);
		if ("2".equals(taskFeedback.getFeedbackStatus()) && tempTaskFeedback.getFeedbackTime() == null) {
			taskFeedback.setFeedbackTime(new Date());
		}
		dcSupTaskFeedbackService.save(taskFeedback);

		// 设置一个临时变量来记录这条反馈放到审核表中时的id，在消息中使用
		String tempAuditId = "";

		if (Dict.FeedbackStatus.STATUS_2.equals(taskFeedback.getFeedbackStatus())) {
			if (StringUtils.isNotBlank(taskFeedback.getAuditorCode())) {
				tempAuditId = IdGen.nextId();
				// 这个地方在网络卡的情况下多次点击反馈会生成多条审核记录
				if(dcSupTaskAuditService.getAuditListInfo(taskFeedback.getId(),"3").size()!=0){
					dcSupTaskAuditService.deleteAuditFeedback(taskFeedback.getId(),"3");
				}
				String s = dcSupTaskAuditService.addAuditInfo(tempAuditId, taskFeedback.getId(), taskFeedback.getTaskId(), Dict.TargetType.TYPE_2, Dict.AuditType.TYPE_3, taskFeedback.getAuditorCode(), taskFeedback.getAuditorName(), "");
				if (StringUtils.isNotBlank(s)) {
					dcSupTaskFeedbackService.delete(taskFeedback);
					return s;
				}
			} else {
				// 没有审核人，判断是否走秘书一科流程
				DcSupTaskInfo dcSupTaskInfo = dcSupTaskInfoService.get(taskFeedback.getTaskId());
				if (StringUtils.equals("2", dcSupTaskInfo.getNormalFlag())) {
					tempAuditId = IdGen.nextId();
					// 这个地方在网络卡的情况下多次点击反馈会生成多条审核记录
					if(dcSupTaskAuditService.getAuditListInfo(taskFeedback.getId(),"4").size()!=0){
						dcSupTaskAuditService.deleteAuditFeedback(taskFeedback.getId(),"4");
					}
					String s = dcSupTaskAuditService.addAuditInfo(tempAuditId, taskFeedback.getId(), taskFeedback.getTaskId(), Dict.TargetType.TYPE_2, Dict.AuditType.TYPE_4, null, null, "OFFICE_MEMBER");
					if (StringUtils.isNotBlank(s)) {
						dcSupTaskFeedbackService.delete(taskFeedback);
						return s;
					}
				} else {
					// 不是秘书一科流程，则走任务部署人审核
					tempAuditId = IdGen.nextId();
					// 这个地方在网络卡的情况下多次点击反馈会生成多条审核记录
					if(dcSupTaskAuditService.getAuditListInfo(taskFeedback.getId(),"5").size()!=0){
						dcSupTaskAuditService.deleteAuditFeedback(taskFeedback.getId(),"5");
					}
					String s = dcSupTaskAuditService.addAuditInfo(tempAuditId, taskFeedback.getId(), taskFeedback.getTaskId(), Dict.TargetType.TYPE_2, Dict.AuditType.TYPE_5, dcSupTaskInfo.getCreateBy(), UserUtils.get(dcSupTaskInfo.getCreateBy()).getUserName(), "");
					if (StringUtils.isNotBlank(s)) {
						dcSupTaskFeedbackService.delete(taskFeedback);
						return s;
					}
				}
			}
			//写入statue表
			dcSupTaskStatusService.addStatus(taskFeedback.getId(), Dict.TargetType.TYPE_3, "3", "已接收");
		}

		DcSupTaskInfo dcSupTaskInfoRes = dcSupTaskFeedbackService.getInfoByActionId(taskFeedback.getActionId());
		//选择审批人的时候写入是否审批
		if (StringUtils.isNotBlank(taskFeedback.getAuditorCode())) {
			// 6普任务反馈，选择审核人，向审核人发送消息
			// 7秘任务反馈，选择审核人，向审核人发送消息
			// 8细任务反馈，选择审核人，向审核人发送消息
			if (Dict.FeedbackStatus.STATUS_2.equals(taskFeedback.getFeedbackStatus())) {
//				PcMsgContent msg = new PcMsgContent();
//				msg.setTitle("提示信息");
//				// 任务部署
//				msg.setContent("您有一个任务:\"" + dcSupTaskInfoRes.getTaskTitle() + "\"," + dcSupTaskInfoRes.getTaskLeaderName() + "单位已反馈,请及时查看");
//				msg.addButton("任务反馈审核", "/a/audit/dcSupTaskAudit/form?id=" + tempAuditId + "&taskLeaderOrgName=" + dcSupTaskInfoRes.getTaskLeaderOrgName());
//				MsgPushUtils.push(msg, tempAuditId, "audit_feedback_shenheren", taskFeedback.getAuditorCode());
				//发送易政网消息
				MsgDetail msgDetail = new MsgDetail();
				msgDetail.setSendid(UserUtils.getUser().getUserCode());
				msgDetail.setSubjectid(taskFeedback.getAuditorCode());
				msgDetail.setMesg("您有一个任务:\"" + dcSupTaskInfoRes.getTaskTitle() + "\"," + dcSupTaskInfoRes.getTaskLeaderName() + "单位已反馈,请及时登录系统查看");
				lehandYzwPushTask.pushYzwShortMsg(msgDetail);
				//新增待办-选择审核人给审核人增加待办
				dcSupBacklogService.add("督查督办","任务反馈审核","任务反馈审核人审核","提示信息"
						,"您有一个任务:" + dcSupTaskInfoRes.getTaskTitle() + "," + dcSupTaskInfoRes.getTaskLeaderName() + "单位已反馈,请及时查看"
						,"/a/audit/dcSupTaskAudit/form?id=" + tempAuditId + "&taskLeaderOrgName=" + dcSupTaskInfoRes.getTaskLeaderOrgName(),""
						,tempAuditId,"task_audit_feedback",taskFeedback.getAuditorCode()
						,taskFeedback.getTaskId(),taskFeedback.getActionId());
			}
			taskFeedback.setAuditFlag("1");
		} else {
			taskFeedback.setAuditFlag("0");
			// 8普任务反馈，向任务部署人发送消息
			// 10细任务反馈，向任务部署人发送消息
			if (Dict.FeedbackStatus.STATUS_2.equals(taskFeedback.getFeedbackStatus())) {
				if ("1".equals(dcSupTaskInfoRes.getNormalFlag()) || "3".equals(dcSupTaskInfoRes.getNormalFlag())) {
//					PcMsgContent msg = new PcMsgContent();
//					msg.setTitle("提示信息");
//					// 任务部署
//					msg.setContent("您有一个任务:\"" + dcSupTaskInfoRes.getTaskTitle() + "\"任务反馈待审核,请及时查看");
//					msg.addButton("任务反馈审核", "/a/audit/dcSupTaskAudit/form?id=" + tempAuditId + "&taskLeaderOrgName=" + dcSupTaskInfoRes.getTaskLeaderOrgName());
//					MsgPushUtils.push(msg, tempAuditId, "audit_feedback_bushuren", dcSupTaskInfoRes.getCreateBy());
					//发送易政网消息
					MsgDetail msgDetail = new MsgDetail();
					msgDetail.setSendid(UserUtils.getUser().getUserCode());
					msgDetail.setSubjectid(dcSupTaskInfoRes.getCreateBy());
					msgDetail.setMesg("您有一个任务:\"" + dcSupTaskInfoRes.getTaskTitle() + "\"任务反馈待审核,请及时登录系统查看");
					lehandYzwPushTask.pushYzwShortMsg(msgDetail);
					//新增待办-未选择审核人给创建人增加审核待办
					dcSupBacklogService.add("督查督办","任务反馈审核","任务反馈部署人审核","提示信息"
							,"您有一个任务:" + dcSupTaskInfoRes.getTaskTitle() + "任务反馈待审核,请及时查看"
							,"/a/audit/dcSupTaskAudit/form?id=" + tempAuditId + "&taskLeaderOrgName=" + dcSupTaskInfoRes.getTaskLeaderOrgName(),""
							,tempAuditId,"task_audit_feedback",dcSupTaskInfoRes.getCreateBy()
							,taskFeedback.getTaskId(),taskFeedback.getActionId());
				}
				// 9秘任务反馈，向科室成员发送消息
				if ("2".equals(dcSupTaskInfoRes.getNormalFlag())) {
					List<SysBasicUser> officeMembers = sysBasicDao.getUserByOfficeAndRole(dcSupTaskInfoRes.getTaskSupOrg(), "SECRETARY_ONE");

					for (SysBasicUser user : officeMembers) {
//						PcMsgContent msg = new PcMsgContent();
//						msg.setTitle("提示信息");
//						msg.setContent("您有一个任务:\"" + dcSupTaskInfoRes.getTaskTitle() + "\"任务反馈待审核,请及时查看");
//						msg.addButton("任务反馈审核", "/a/audit/dcSupTaskAudit/form?id=" + tempAuditId + "&taskLeaderOrgName=" + dcSupTaskInfoRes.getTaskLeaderOrgName());
//						MsgPushUtils.push(msg, tempAuditId, "audit_feedback_keshichengyuan", user.getUserCode());
						//发送易政网消息
						MsgDetail msgDetail = new MsgDetail();
						msgDetail.setSendid(UserUtils.getUser().getUserCode());
						msgDetail.setSubjectid(user.getUserCode());
						msgDetail.setMesg("您有一个任务:\"" + dcSupTaskInfoRes.getTaskTitle() + "\"任务反馈待审核,请及时登录系统查看");
						lehandYzwPushTask.pushYzwShortMsg(msgDetail);
					}
					//新增待办
					dcSupBacklogService.addBasic("督查督办","任务反馈审核","任务反馈科室成员审核","提示信息"
							,"您有一个任务:\"" + dcSupTaskInfoRes.getTaskTitle() + "\"任务反馈待审核,请及时查看"
							,"/a/audit/dcSupTaskAudit/form?id=" + tempAuditId + "&taskLeaderOrgName=" + dcSupTaskInfoRes.getTaskLeaderOrgName(),dcSupTaskInfoRes.getTaskSupOrg()
							,tempAuditId,"task_audit_feedback",officeMembers
							,taskFeedback.getTaskId(),taskFeedback.getActionId());
				}
			}
		}

		//任务被驳回后重新发起置为已办
		dcSupBacklogService.doBacklog(taskFeedback.getId(),"task_feedback");
		//定时任务的待办置为已办
		dcSupBacklogService.doBacklogDate(taskFeedback.getActionId(),"task_yuqi",taskFeedback.getFeedbackEndTimeStr());

		return "";
    }

	/**
	 * 查询牵头领导批示内容
	 * @param dcSupTaskActionExplain
	 * @return
	 */
	public Page<DcSupTaskActionExplain> getLeaderExplain(DcSupTaskActionExplain dcSupTaskActionExplain) {
		return dcSupTaskActionExplain.getPage().setList(taskReceiveDao. getLeaderExplain(dcSupTaskActionExplain));
	}

	public void cuiban(String id) {
		DcSupTaskAction action = dcSupTaskActionService.get(id);
		DcSupTaskInfo info = dcSupTaskInfoService.get(action.getTaskId());
		// 任务接收催办
		PcMsgContent msg = new PcMsgContent();
		msg.setTitle("提示信息");
		msg.setContent("您有一个任务:\""+info.getTaskTitle()+",请及时查看");
		msg.addButton("任务待办", "/a/action/dcSupTaskAction/noCompleteView");
		MsgPushUtils.push(msg, info.getId() + "_" + action.getLeaderOrgCode(), "feedback_msg", action.getTransferOrgCode());
		//发送易政网消息
		MsgDetail msgDetail = new MsgDetail();
		msgDetail.setSendid(UserUtils.getUser().getUserCode());
		msgDetail.setSubjectid(action.getTransferOrgCode());
		msgDetail.setMesg("您有一个任务:\""+info.getTaskTitle()+",请及时登录系统查看");
		lehandYzwPushTask.pushYzwShortMsg(msgDetail);
	}
	public void cuiban2(String id) {
		DcSupTaskAction action = dcSupTaskActionService.get(id);
		DcSupTaskInfo info = dcSupTaskInfoService.get(action.getTaskId());
		//所有任务部署催办
		if(StringUtils.isNotBlank(action.getTransferOrgCode())){
			PcMsgContent msg = new PcMsgContent();
			msg.setTitle("提示信息");
			msg.setContent("您有一个任务:\""+info.getTaskTitle()+",请及时查看");
			MsgPushUtils.push(msg, info.getId(), "renwuyuqixinxicuiban", action.getTransferOrgCode());
			//发送易政网消息
			MsgDetail msgDetail = new MsgDetail();
			msgDetail.setSendid(UserUtils.getUser().getUserCode());
			msgDetail.setSubjectid(action.getTransferOrgCode());
			msgDetail.setMesg("您有一个任务:\""+info.getTaskTitle()+",请及时登录系统查看");
			lehandYzwPushTask.pushYzwShortMsg(msgDetail);
		}else {
			List<OfficeUser> userByOrg = dcSupTaskActionDao.getUserByOrg("OTSTRANSFER", action.getLeaderOrgCode());
			for (OfficeUser user : userByOrg) {
				PcMsgContent msg = new PcMsgContent();
				msg.setTitle("提示信息");
				msg.setContent("您有一个任务:\"" + info.getTaskTitle() + ",请及时查看");
				MsgPushUtils.push(msg, info.getId(), "renwucuiban", user.getUserCode());
				//发送易政网消息
				MsgDetail msgDetail = new MsgDetail();
				msgDetail.setSendid(UserUtils.getUser().getUserCode());
				msgDetail.setSubjectid(user.getUserCode());
				msgDetail.setMesg("您有一个任务:\"" + info.getTaskTitle() + ",请及时登录系统查看");
				lehandYzwPushTask.pushYzwShortMsg(msgDetail);
			}
		}
	}

    public Page<TaskReceiveDto> feedbackListData(TaskReceiveDto taskReceive) {
		return taskReceive.getPage().setList(dao.feedbackListData(taskReceive));
    }

    public void updateFeedbackTime(DcSupTaskFeedback feedback) {
		dao.updateFeedbackTime(feedback);
    }

	public List<DcSupTaskFeedback> getfeedbackListById(String actionId,String feedbackId) {
		return dao.getfeedbackListById(actionId);
	}

	public Map<String, List<DcSupTaskFeedback>> getFeedbackListByIds(List<String> ids) {
		Map<String, List<DcSupTaskFeedback>> result=null;
		List<DcSupTaskFeedback> listByIds = dao.getFeedbackListByIds(ids);
		if (CollectionUtils.isEmpty(listByIds)){
			result =new HashMap<>();
		}else{
			result = listByIds.stream().collect(Collectors.groupingBy(s -> s.getActionId()));
		}
		return result;
	}
	@Transactional(readOnly=false)
	public String feedbackProvince(DcSupTaskFeedbackProvinceExt dcSupTaskFeedbackProvinceExt) throws Exception {

		String upData_url = Global.getConfig("platform.dcDataTransfer.upData");
		String token = Global.getConfig("platform.dcDataTransfer.token");
		String orgCode = Global.getConfig("platform.dcDataTransfer.orgCode");
		String url = upData_url;
		RestTemplate restTemplate = new RestTemplate();
		//提交参数设置
		DcSupTaskFeedbackProvince dcSupTaskFeedbackProvince =	new DcSupTaskFeedbackProvince();
		BeanUtils.copyProperties(dcSupTaskFeedbackProvinceExt,dcSupTaskFeedbackProvince);
		String dataContent = JSONObject.toJSONString(dcSupTaskFeedbackProvince);
		MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<>();
		HttpHeaders headers = new HttpHeaders();
		headers.add("Accept", MediaType.APPLICATION_JSON.toString());
		headers.add("token",token);
		postParameters.add("orgCode", orgCode);
		postParameters.add("bizKey","reportData");
		postParameters.add("dataContent", dataContent);
		HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(postParameters, headers);
		if(!StringUtils.equals(dcSupTaskFeedbackProvinceExt.getDecomposeFlag(),"1")){
			JSONObject body1 = restTemplate.postForObject(url, request, JSONObject.class);
			Integer code = (Integer) body1.get("code");
			if (code != 0) {
				throw new Exception("该省办任务已经省办平台办理过，提交失败");
			}
		}
		DcSupTaskFeedback taskFeedback = new DcSupTaskFeedback();
		taskFeedback.setId(dcSupTaskFeedbackProvinceExt.getId());
		taskFeedback.setTaskId(dcSupTaskFeedbackProvinceExt.getTaskId());
		taskFeedback.setActionId(dcSupTaskFeedbackProvinceExt.getActionId());
		taskFeedback.setDispatchFlag("0");
		taskFeedback.setFeedbackContent(dcSupTaskFeedbackProvinceExt.getCheckMsg());
		taskFeedback.setFeedbackAdvice(dcSupTaskFeedbackProvinceExt.getProblemReason());
		taskFeedback.setFeedbackMeasure(dcSupTaskFeedbackProvinceExt.getMeasuresContent());
		taskFeedback.setFeedbackEndTimeStr(dcSupTaskFeedbackProvinceExt.getReportDate());
		taskFeedback.setFeedbackName(dcSupTaskFeedbackProvinceExt.getReportBy());
		taskFeedback.setFeedbackPhone(dcSupTaskFeedbackProvinceExt.getReportContactPhone());
		taskFeedback.setFeedbackProgress("1");
		taskFeedback.setFeedbackRate(100.0);
		taskFeedback.setFeedbackStatus("3");
		taskFeedback.setFeedbackTime(new Date());
		taskFeedback.setIsNewRecord(false);
		taskFeedback.setFeedbackProgress("3");
		taskFeedback.setProvinceJson(dataContent);
	    dcSupTaskFeedbackService.save(taskFeedback);
		DcSupTaskAction action = new DcSupTaskAction();
		action.setId(dcSupTaskFeedbackProvinceExt.getActionId());
		action.setTaskStatus(Dict.TaskStatus.STATUS_4);
		action.setTaskProgress("4");
		dcSupTaskActionService.update(action);
		dcSupBacklogService.doBacklog(action.getId(),"task_transfer");
		FileUploadUtils.saveFileUpload(dcSupTaskFeedbackProvince, dcSupTaskFeedbackProvince.getBizId(), "dcSupTaskFeedbackProvince_type1");
		FileUploadUtils.saveFileUpload(dcSupTaskFeedbackProvince, dcSupTaskFeedbackProvince.getBizId(), "dcSupTaskFeedbackProvince_type2");
		MinioUtils minioUtils = SpringUtils.getBean(MinioUtils.class);

		List<FileUpload> dcSupTaskFeedbackProvince_type1s = FileUploadUtils.findFileUpload(dcSupTaskFeedbackProvince.getBizId(), "dcSupTaskFeedbackProvince_type1");
		List<FileUpload> dcSupTaskFeedbackProvince_type2s = FileUploadUtils.findFileUpload(dcSupTaskFeedbackProvince.getBizId(), "dcSupTaskFeedbackProvince_type2");
		if(!StringUtils.equals(dcSupTaskFeedbackProvinceExt.getDecomposeFlag(),"1")){
		for(FileUpload type1:dcSupTaskFeedbackProvince_type1s){
			uploadToRemote(restTemplate, dcSupTaskFeedbackProvince, minioUtils, type1, "1",token,orgCode);
		}

		for(FileUpload type2:dcSupTaskFeedbackProvince_type2s){
			uploadToRemote(restTemplate, dcSupTaskFeedbackProvince, minioUtils, type2, "2",token,orgCode);
		}
		}
		return "";
	}

	private void uploadToRemote(RestTemplate restTemplate, DcSupTaskFeedbackProvince dcSupTaskFeedbackProvince, MinioUtils minioUtils, FileUpload type1, String s,String token,String orgCode) {
		String fileFullName = ClassUtils.getDefaultClassLoader().getResource("").getPath() + type1.getFileName();
		minioUtils.getRemoteFile(type1.getFileEntity(), fileFullName);
		File file1 = new File(fileFullName);
		// 1、封装请求头
		HttpHeaders headersFile1 = new HttpHeaders();
		MediaType typeFile1 = MediaType.parseMediaType("multipart/form-data");
		headersFile1.setContentType(typeFile1);
		headersFile1.setContentLength(file1.length());
		headersFile1.setContentDispositionFormData("media", file1.getName());
		headersFile1.add("token", token);
		// 2、封装请求体
		MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
		FileSystemResource resource = new FileSystemResource(file1);
		param.add("file", resource);
		param.add("orgCode", orgCode);
		param.add("type", s);
		param.add("bizId", dcSupTaskFeedbackProvince.getBizId());
		// 3、封装整个请求报文
		HttpEntity<MultiValueMap<String, Object>> formEntityFile1 = new HttpEntity<>(param, headersFile1);
		// 4、发送请求
		String upFile_url = Global.getConfig("platform.dcDataTransfer.upFile");
		ResponseEntity<String> data = restTemplate.postForEntity(upFile_url, formEntityFile1, String.class);
		file1.delete();
	}

	public void feedbackReject(DcSupTaskFeedbackReject dcSupTaskFeedbackReject) throws Exception {
		String upData_url = Global.getConfig("platform.dcDataTransfer.upData");
		String token = Global.getConfig("platform.dcDataTransfer.token");
		String orgCode = Global.getConfig("platform.dcDataTransfer.orgCode");
		String url = upData_url+"?orgCode=%s&bizKey=%s&dataContent=%s";
		RestTemplate restTemplate = new RestTemplate();
		HttpHeaders headers = new HttpHeaders();
		MediaType type = MediaType.parseMediaType("text/plain; charset=UTF-8");
		headers.setContentType(type);
		headers.add("Accept", MediaType.APPLICATION_JSON.toString());
		headers.add("token",token);
		//提交参数设置
		DcSupTaskFeedbackRejectParam param =	new DcSupTaskFeedbackRejectParam();
		BeanUtils.copyProperties(dcSupTaskFeedbackReject,param);
		String dataContent = JSONObject.toJSONString(param);
		url = String.format(url, orgCode, "returnData", "{dataContent}");
		HttpEntity formEntity = new HttpEntity<>(headers);
		//使用JSONObject，不需要创建实体类VO来接受返参，缺点是别人不知道里面有哪些字段,即不知道有那些key

			JSONObject body1 = restTemplate.postForObject(url, formEntity, JSONObject.class,dataContent);
			Integer code = (Integer) body1.get("code");
			if (code != 0) {
				throw new Exception("提交失败");
			}

		DcSupTaskFeedback taskFeedback = new DcSupTaskFeedback();
		taskFeedback.setId(dcSupTaskFeedbackReject.getId());
		taskFeedback.setTaskId(dcSupTaskFeedbackReject.getTaskId());
		taskFeedback.setActionId(dcSupTaskFeedbackReject.getActionId());
		taskFeedback.setDispatchFlag("0");
		taskFeedback.setFeedbackContent("申请退回");
		taskFeedback.setFeedbackAdvice("申请退回");
		taskFeedback.setFeedbackMeasure("申请退回");
		taskFeedback.setFeedbackName(dcSupTaskFeedbackReject.getOperName());
		taskFeedback.setFeedbackPhone(dcSupTaskFeedbackReject.getOperTel());
		taskFeedback.setFeedbackRate(100.0);
		taskFeedback.setFeedbackStatus("3");
		taskFeedback.setFeedbackTime(new Date());
		taskFeedback.setIsNewRecord(false);
		taskFeedback.setFeedbackProgress("3");
		taskFeedback.setProvinceJson(dataContent);
		dcSupTaskFeedbackService.save(taskFeedback);
		DcSupTaskAction action = new DcSupTaskAction();
		action.setId(dcSupTaskFeedbackReject.getActionId());
		action.setTaskStatus(Dict.TaskStatus.STATUS_4);
		action.setTaskProgress("4");
		dcSupTaskActionService.update(action);
		dcSupBacklogService.doBacklog(action.getId(),"task_transfer");
	}
}